package com.nuanshui.heatedloan.configBehavior;

import java.util.List;
import java.util.Map;

import com.alibaba.dubbo.config.annotation.Reference;
import com.nuanshui.heatedloan.constant.GlobalParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nuanshui.framework.res.ResourceFacade;
import com.nuanshui.framework.utils.LogUtil;
import com.nuanshui.heatedloan.baseservice.facade.PictureConfigService;
import com.nuanshui.heatedloan.baseservice.model.SystemPicture;

/**
 * Created by zxh on 2016/11/19.
 */
@Repository
public class ImageConfigBehavior extends ConfigBehavior {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Reference(url = GlobalParam.BASESERVICE_DUBBO_SERVER, timeout = GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.BASESERVICE_DUBBO_SERVER_VERSION)
    private PictureConfigService pictureConfigService;

    @Override
	public void doInvoke() {

        LogUtil.info(logger, "根据屏幕尺寸:" + getScreenSize() + "获取图片配置");

        loadLaunchImgUrl();
    }

    private void loadLaunchImgUrl() {
        Map<String, Object> map = getMap();
        String screenSize = getScreenSize();
        // 获取启动图片
        SystemPicture launchImg = pictureConfigService.findFirstLaunchPicture(screenSize);
        if (launchImg!=null) {
            map.put("launchImgUrl", launchImg.getLaunchImageUrl());
            map.put("launchImgAccessUrl", launchImg.getAccessUrl());
        }
    }
}
